package com.lh.java.io;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class FileCopyUseBufferedInputStream {
	public static void main(String args[]) {

		BufferedInputStream bis = null;

		BufferedOutputStream bos = null;

		byte buf[] = new byte[100];

		try {

			bis = new BufferedInputStream(new FileInputStream("persia.mp3"));

			bos = new BufferedOutputStream(new FileOutputStream(
					"persia_copy.mp3"));

			int len = 0;

			while (true) {

				len = bis.read(buf);

				if (len <= 0)
					break;

				bos.write(buf, 0, len);

			}

			bos.flush();// 缓冲区只有满时才会将数据输出到输出流，用flush()将未满的缓冲区中数据强制输出

		} catch (Exception e) {

			e.printStackTrace();

		} finally {

			if (bis != null)
				try {
					bis.close();
				} catch (Exception e) {
					e.printStackTrace();
				}

			if (bos != null)
				try {
					bos.close();
				} catch (Exception e) {
					e.printStackTrace();
				}

		}
	}
}
